﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using JsonTest1.Data;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;

namespace JsonTest1.Json
{
    public class AlbumBuilder: JSONBuilder<Album>
    {

        public override Album Build(JObject jsonObject)
        {
            Album album = new Album();
            album.Image = (string)jsonObject["image"];
            album.Name = (string)jsonObject["name"];
            album.Id = (int)jsonObject["id"];

            try
            {
                album.ArtistName = (string)jsonObject["artist_name"];
            }
            catch (JsonException e)
            {
                if (root.Length == 0)
                {
                    throw e;
                }
            }

            try
            {
                album.Rating = (float)jsonObject["rating"];
            }
            catch (JsonException e)
            {
                album.Rating = -1;
            }

            return album;
        }

    }
}
